package com.zsc.shixun.controller;

import com.zsc.shixun.common.CommonResult;
import com.zsc.shixun.common.ResultCode;
import com.zsc.shixun.common.ResultUtil;
import com.zsc.shixun.exception.ApiException;
import com.zsc.shixun.model.test;
import org.springframework.security.access.annotation.Secured;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * <p>
 * 张跃的测试类
 * </p>
 *
 * @author ZWYZY
 * @since 2020/6/9
 */
@Controller
//@RequestMapping("/test")
public class TestController {
    @RequestMapping("/test")
    @ResponseBody
    public CommonResult test() {
        return ResultUtil.success();
    }

    @RequestMapping("/test1")
    @ResponseBody
    public CommonResult test1() {
        int i = 0;
        if (i == 0) {
            throw new ApiException(ResultCode.REGIST_ERROR);
        }

        return ResultUtil.success();
    }

    @PostMapping("/test2")
    @ResponseBody
    public CommonResult test2(int i) {
        return ResultUtil.success();
    }

    @RequestMapping("/test3")
    @ResponseBody
    public CommonResult test3(@Validated test test) {
        return ResultUtil.success();
    }

    @RequestMapping("/")
//    @Secured(value = "ROLE_user")
    public String toIndex() {
        return "redirect:/unAuthorize/";
    }

    @GetMapping("/deny")
    @ResponseBody
    public CommonResult throwDeny() {
        return new CommonResult(ResultCode.AUTHORITY_HAS_EXIST);

    }
    @GetMapping("/get")
    public void getData(@RequestParam String length)
    {

        Double data=Double.parseDouble(length);
    }
    public double getPerimeter(double c1, double c2, double c3) {
        return c1 + c2 + c3;
    }

    @GetMapping("/url/{c1}/{c2}/{c3}")
    public double calArea(@PathVariable String c1,@PathVariable String c2,@PathVariable String c3){
        double a=Double.parseDouble(c1);
        double b=Double.parseDouble(c2);
        double c=Double.parseDouble(c3);
        double s = 0d;
        double p = getPerimeter(a, b, c) / 2;
        s = Math.sqrt(p * (p - a) * (p - b) * (p - c));

        return s;
    }



}
